package logic

import (
	"context"
	"errors"
	"novel-sys/model/mysql"
	"strings"

	"novel-sys/goods/goods"
	"novel-sys/goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentAddLogic) CommentAdd(in *goods.CommentAddRequest) (*goods.CommentAddResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.Comment{
		UserId:  in.UserId,
		NovelId: in.NovelId,
		Comment: in.Comment,
	}
	if strings.Contains("抄袭", in.Comment) || strings.Contains("涉政", in.Comment) {
		return nil, errors.New("敏感")
	}
	if err := data.CommentAdd(mysql.DB); err != nil {
		return nil, err
	}
	return &goods.CommentAddResponse{
		CommentId: int64(data.ID),
	}, nil
}
